package com.wc.alorithm_luogu._模拟.P1030_求先序排列;

import java.util.Scanner;

/**
 * @Author congge
 * @Date 2024/1/25 21:31
 * @description 求先序排列
 * https://www.luogu.com.cn/problem/P1030
 */
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s1 = sc.next();
        String s2 = sc.next();
        dfs(s1, s2);
    }

    /**
     * @param s1 中序遍历
     * @param s2 后续遍历
     */
    static void dfs(String s1, String s2) {
        if (s1.length() == 0) return;
        int len = s1.length();
        char root = s2.charAt(len - 1);
        int pos = s1.indexOf(root);
        String s1l = s1.substring(0, pos);
        String s1r = s1.substring(pos + 1, len);

        String s2l = s2.substring(0, pos);
        String s2r = s2.substring(pos, len - 1);
        System.out.print(root);
        dfs(s1l, s2l);
        dfs(s1r, s2r);
    }
}
